namespace cnVery.bbs.UI.Forum
{
    using cnVery.bbs.Kernel;
    using cnVery.Controls;
    using cnVery.Utils;
    using System;
    using System.Data;
    using System.Web;
    using System.Web.UI.WebControls;

    public class choose_skin : Main
    {
        protected Repeater list;

        private void InitializeComponent()
        {
            base.Load += new EventHandler(this.Page_Load);
            this.list.ItemCreated += new RepeaterItemEventHandler(this.Roll);
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (base.IsPostBack)
            {
                this.Save();
            }
            DataSet set = new DataSet();
            set.ReadXml(Fetch.MapPath("skin/skin.xml"));
            this.list.DataSource = set.Tables[0];
            this.list.DataBind();
            this.Finish();
        }

        private void Roll(object sender, RepeaterItemEventArgs e)
        {
            DataRowView dataRowViewFromRepeaterItemEventArgs = this.GetDataRowViewFromRepeaterItemEventArgs(e);
            if (dataRowViewFromRepeaterItemEventArgs != null)
            {
                Span span = e.Item.FindControl("label") as Span;
                Img img = e.Item.FindControl("thumbnail") as Img;
                span.Text = string.Concat(new object[] { "<input type='radio' name='item' id='", dataRowViewFromRepeaterItemEventArgs["folder"], "' value='", dataRowViewFromRepeaterItemEventArgs["folder"], "' class='smallbox'", (dataRowViewFromRepeaterItemEventArgs["folder"].ToString() == base.skin) ? " checked='checked'" : "", " />  <label for='", dataRowViewFromRepeaterItemEventArgs["folder"], "'>", dataRowViewFromRepeaterItemEventArgs["name"], "</label>" });
                img.Src = dataRowViewFromRepeaterItemEventArgs["thumbnail"].ToString();
                img.Href = "index.aspx?skin=" + dataRowViewFromRepeaterItemEventArgs["folder"];
            }
        }

        private void Save()
        {
            if (base.skin != this.Post("item"))
            {
                HttpCookie cookie = Cookie.Get("skin");
                cookie.Value = this.Post("item");
                cookie.Expires = DateTime.Now.AddYears(1);
                Cookie.Save(cookie);
                base.Response.Redirect("choose_skin.aspx");
            }
        }
    }
}

